package option;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Delete implements Ioperate{
    @Override
    public void work(BookList bookList) {
        System.out.println("输入你要删除的书名：");
        Scanner scan = new Scanner(System.in);
        String bookName = scan.nextLine();

        int size = bookList.getCurSize();
        int i = 0;
        while(i<size){
            if(bookList.getBooks(i).getName().equals(bookName)){
                for (int j = i; j < size - 1; j++) {
                    Book book = bookList.getBooks(i+1);
                    bookList.setBooks(i,book);
                }
                bookList.setCurSize(size-1);
                System.out.println(bookName + "删除成功.......");
            }
            i++;
        }

        if(i==size){
            System.out.println("未找到本书");
        }
    }
}
